<!DOCTYPE html>

<html lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>日志记录（Logging） &mdash; Phalcon 3.0.1 文档</title>
    <meta name="keywords" content="php, phalcon, phalcon php, php framework, faster php framework">
    <link rel="stylesheet" type="text/css" href="http://cdn.staticfile.org/twitter-bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/www/css/phalcon.min.css" />
    <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400' rel='stylesheet' type='text/css'>
    <link href="//fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css" />
    <!--
    EUROPE <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=latin-ext' rel='stylesheet' type='text/css'>
    GREEK <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=greek-ext' rel='stylesheet' type='text/css'>
    RUSSIA <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=cyrillic-ext,latin' rel='stylesheet' type='text/css'>
    -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="../static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../static/docs.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script src="http://cdn.staticfile.org/jquery/1.8.1/jquery.min.js"></script>
    <script type="text/javascript" src="../static/docs.js"></script>
    <link rel="shortcut icon" href="../static/favicon.ico"/>
    <link rel="top" title="Phalcon 3.0.1 文档" href="../index.html" />
    <link rel="next" title="注释解析器（Annotations Parser）" href="annotations.html" />
    <link rel="prev" title="Class Autoloader" href="loader.html" /> 
  </head>
  <body>

<header class="page-header">
    <nav class="navbar" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-container">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand phalcon-logo" href="/"><span itemprop="name" class="sr-only">Phalcon PHP</span></a>
            </div>

            <div class="collapse navbar-collapse navbar-right" id="main-menu-container">
                <ul class="nav navbar-nav main-menu">
                  <li class="first"><a href="//phalconphp.com/en/download" class="header-nav-link">Download</a></li>
                  <li><a href="//docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="//forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="//blog.phalconphp.com/" class="header-nav-link" target="_blank">Blog</a></li>
                  <li><a href="//phalconist.com/" class="header-nav-link" target="_blank">Resources</a></li>
                  <li><a href="//phalconphp.com/en/about">About</a></li>
                  <li><div align="right">
                      <iframe src="https://ghbtns.com/github-btn.html?user=phalcon&amp;repo=cphalcon&amp;type=watch&amp;count=true&amp;size=large"
      allowtransparency="true" frameborder="0" scrolling="0" width="152px" height="30px"></iframe>
                    </div></li>
                </ul>
            </div>
        </div>
    </nav>
  </header>

<div class="heading">
    <div class="container">
        <div class="row">
            <h2>Documentation</h2>
        </div>
    </div>
</div>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="annotations.html" title="注释解析器（Annotations Parser）"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="loader.html" title="Class Autoloader"
             accesskey="P">上一页</a> |</li>
        <li><a href="//phalconphp.com">Home</a> &raquo;</li>
        <li><a href="../index.html">Phalcon 3.0.1 文档</a> &raquo;</li> 
      </ul>
    </div>  

      <table width="100%" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td class="primary-box" width="25%" valign="top">
            <div>
            <div id="searchbox" style="">
                <!--<form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="search" name="q" size="25" placeholder="Search">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>-->
                <div style="width:200px;padding:10px">
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
            </div>
            </div>
            <div style="padding:5px;padding-left:10px">
              <div id="carbonads-container">
                <div class="carbonad"><div id="azcarbon"></div>
                <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=phalconphpcom" id="_carbonads_js"></script>
                </div></div>
            </div>
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference internal" href="#">日志记录（Logging）</a><ul>
<li><a class="reference internal" href="#adapters">适配器（Adapters）</a></li>
<li><a class="reference internal" href="#creating-a-log">创建日志（Creating a Log）</a></li>
<li><a class="reference internal" href="#transactions">事务（Transactions）</a></li>
<li><a class="reference internal" href="#logging-to-multiple-handlers">使用多个处理程序进行日志记录（Logging to Multiple Handlers）</a></li>
<li><a class="reference internal" href="#message-formatting">信息格式（Message Formatting）</a><ul>
<li><a class="reference internal" href="#line-formatter">行格式化处理（Line Formatter）</a></li>
<li><a class="reference internal" href="#implementing-your-own-formatters">自定义格式处理（Implementing your own formatters）</a></li>
</ul>
</li>
<li><a class="reference internal" href="#id1">适配器(Adapters)</a><ul>
<li><a class="reference internal" href="#stream-logger">数据流日志记录器（Stream Logger）</a></li>
<li><a class="reference internal" href="#file-logger">文件日志记录器（File Logger）</a></li>
<li><a class="reference internal" href="#syslog-syslog-logger">Syslog 日志记录器（Syslog Logger）</a></li>
<li><a class="reference internal" href="#firephp-firephp-logger">FirePHP 日志记录器（FirePHP Logger）</a></li>
<li><a class="reference internal" href="#implementing-your-own-adapters">自定义适配器（Implementing your own adapters）</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="loader.html" title="上一章">&lt; Class Autoloader</a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="annotations.html" title="下一章">注释解析器（Annotations Parser） &gt;</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../sources/reference/logging.md" rel="nofollow">显示源代码</a></li>
            </ul>
        </td>
          <td class="second-box" valign="top">
            <div class="document">
                <div class="documentwrapper">
                  <div class="bodywrapper">
                    <div class="body" >
                      
  <div class="section" id="logging">
<h1>日志记录（Logging）<a class="headerlink" href="#logging" title="永久链接至标题">¶</a></h1>
<p>Phalcon提供了一个日志记录组件即 <a class="reference internal" href="../api/Phalcon_Logger.html"><em>Phalcon\Logger</em></a>。 我们可以使用此组件输出日志到不同的流中，如文件，系统日志等。
这个组件还提供了其它的功能如日志事务（类似于数据库的事务）， 配置选项， 还可以输出不同的格式，另外还支持多种过滤器。 <a class="reference internal" href="../api/Phalcon_Logger.html"><em>Phalcon\Logger</em></a>
提供了多种日志记录方式，从调试程序到跟踪应用的执行以满足应用的需求。</p>
<div class="section" id="adapters">
<h2>适配器（Adapters）<a class="headerlink" href="#adapters" title="永久链接至标题">¶</a></h2>
<p>此组件使用不同的流适配器来保存日信息。 我们可以按需使用适配器。支持的适配器如下：</p>
</div>
<div class="section" id="creating-a-log">
<h2>创建日志（Creating a Log）<a class="headerlink" href="#creating-a-log" title="永久链接至标题">¶</a></h2>
<p>下面的例子展示了如何创建日志对象及如何添加日志信息：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\File</span> <span class="k">as</span> <span class="nx">FileAdapter</span><span class="p">;</span>

<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileAdapter</span><span class="p">(</span><span class="s2">&quot;app/logs/test.log&quot;</span><span class="p">);</span>



<span class="c1">// These are the different log levels available:</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">critical</span><span class="p">(</span>
    <span class="s2">&quot;This is a critical message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">emergency</span><span class="p">(</span>
    <span class="s2">&quot;This is an emergency message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">debug</span><span class="p">(</span>
    <span class="s2">&quot;This is a debug message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span>
    <span class="s2">&quot;This is an error message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">info</span><span class="p">(</span>
    <span class="s2">&quot;This is an info message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">notice</span><span class="p">(</span>
    <span class="s2">&quot;This is a notice message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">warning</span><span class="p">(</span>
    <span class="s2">&quot;This is a warning message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">alert</span><span class="p">(</span>
    <span class="s2">&quot;This is an alert message&quot;</span>
<span class="p">);</span>



<span class="c1">// You can also use the log() method with a Logger constant:</span>
<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is another error message&quot;</span><span class="p">,</span>
    <span class="nx">Logger</span><span class="o">::</span><span class="na">ERROR</span>
<span class="p">);</span>

<span class="c1">// If no constant is given, DEBUG is assumed.</span>
<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is a message&quot;</span>
<span class="p">);</span>
</pre></div>
</div>
<p>产生的日志信息如下：</p>
<div class="highlight-none"><div class="highlight"><pre>[Tue, 28 Jul 15 22:09:02 -0500][CRITICAL] This is a critical message
[Tue, 28 Jul 15 22:09:02 -0500][EMERGENCY] This is an emergency message
[Tue, 28 Jul 15 22:09:02 -0500][DEBUG] This is a debug message
[Tue, 28 Jul 15 22:09:02 -0500][ERROR] This is an error message
[Tue, 28 Jul 15 22:09:02 -0500][INFO] This is an info message
[Tue, 28 Jul 15 22:09:02 -0500][NOTICE] This is a notice message
[Tue, 28 Jul 15 22:09:02 -0500][WARNING] This is a warning message
[Tue, 28 Jul 15 22:09:02 -0500][ALERT] This is an alert message
[Tue, 28 Jul 15 22:09:02 -0500][ERROR] This is another error message
[Tue, 28 Jul 15 22:09:02 -0500][DEBUG] This is a message
</pre></div>
</div>
<p>You can also set a log level using the <code class="code docutils literal"><span class="pre">setLogLevel()</span></code> method. This method takes a Logger constant and will only save log messages that are as important or more important than the constant:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\File</span> <span class="k">as</span> <span class="nx">FileAdapter</span><span class="p">;</span>

<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileAdapter</span><span class="p">(</span><span class="s2">&quot;app/logs/test.log&quot;</span><span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">setLogLevel</span><span class="p">(</span>
    <span class="nx">Logger</span><span class="o">::</span><span class="na">CRITICAL</span>
<span class="p">);</span>
</pre></div>
</div>
<p>In the example above, only critical and emergency messages will get saved to the log. By default, everything is saved.</p>
</div>
<div class="section" id="transactions">
<h2>事务（Transactions）<a class="headerlink" href="#transactions" title="永久链接至标题">¶</a></h2>
<p>保存日志到适配器如文件(文件系统)是非常消耗系统资源的。 为了减少应用性能上的开销，我们可以使用日志事务。 事务会把日志记录临时的保存到内存中然后再
写入到适配中（此例子中为文件），（这个操作是个原子操作）</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\File</span> <span class="k">as</span> <span class="nx">FileAdapter</span><span class="p">;</span>

<span class="c1">// 生成日志新组件实例</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileAdapter</span><span class="p">(</span><span class="s2">&quot;app/logs/test.log&quot;</span><span class="p">);</span>

<span class="c1">// 开启事务</span>
<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">begin</span><span class="p">();</span>

<span class="c1">// 添加消息</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">alert</span><span class="p">(</span>
    <span class="s2">&quot;This is an alert&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span>
    <span class="s2">&quot;This is another error&quot;</span>
<span class="p">);</span>

<span class="c1">//  保存消息到文件中</span>
<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">commit</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="logging-to-multiple-handlers">
<h2>使用多个处理程序进行日志记录（Logging to Multiple Handlers）<a class="headerlink" href="#logging-to-multiple-handlers" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="../api/Phalcon_Logger.html"><em>Phalcon\Logger</em></a> 也可以同时保存日志信息到多个适配器中：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Multiple</span> <span class="k">as</span> <span class="nx">MultipleStream</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\File</span> <span class="k">as</span> <span class="nx">FileAdapter</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\Stream</span> <span class="k">as</span> <span class="nx">StreamAdapter</span><span class="p">;</span>

<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">MultipleStream</span><span class="p">();</span>



<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">push</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">FileAdapter</span><span class="p">(</span><span class="s2">&quot;test.log&quot;</span><span class="p">)</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">push</span><span class="p">(</span>
    <span class="k">new</span> <span class="nx">StreamAdapter</span><span class="p">(</span><span class="s2">&quot;php://stdout&quot;</span><span class="p">)</span>
<span class="p">);</span>



<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is a message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is an error&quot;</span><span class="p">,</span>
    <span class="nx">Logger</span><span class="o">::</span><span class="na">ERROR</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span>
    <span class="s2">&quot;This is another error&quot;</span>
<span class="p">);</span>
</pre></div>
</div>
<p>信息发送的顺序和处理器（适配器）注册的顺序相同。</p>
</div>
<div class="section" id="message-formatting">
<h2>信息格式（Message Formatting）<a class="headerlink" href="#message-formatting" title="永久链接至标题">¶</a></h2>
<p>此组件使用 formatters 在信息发送前格式化日志信息。 支持下而后格式：</p>
<div class="section" id="line-formatter">
<h3>行格式化处理（Line Formatter）<a class="headerlink" href="#line-formatter" title="永久链接至标题">¶</a></h3>
<p>使用单行格式格式化信息。 默认的格式如下：</p>
<div class="highlight-none"><div class="highlight"><pre>[%date%][%type%] %message%
</pre></div>
</div>
<p>我们可以使用 <code class="code docutils literal"><span class="pre">setFormat()</span></code> 来设置自定义格式。 下面是格式变量：</p>
<table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="79%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">变量</th>
<th class="head">描述</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>%message%</td>
<td>待记录的日志消息</td>
</tr>
<tr class="row-odd"><td>%date%</td>
<td>消息添加的时间</td>
</tr>
<tr class="row-even"><td>%type%</td>
<td>消息类型（使用大写）</td>
</tr>
</tbody>
</table>
<p>下面的例子中展示了如何修改日志格式：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger\Formatter\Line</span> <span class="k">as</span> <span class="nx">LineFormatter</span><span class="p">;</span>

<span class="nv">$formatter</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">LineFormatter</span><span class="p">(</span><span class="s2">&quot;%date% - %message%&quot;</span><span class="p">);</span>

<span class="c1">// 修改日志格式</span>
<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">setFormatter</span><span class="p">(</span><span class="nv">$formatter</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="implementing-your-own-formatters">
<h3>自定义格式处理（Implementing your own formatters）<a class="headerlink" href="#implementing-your-own-formatters" title="永久链接至标题">¶</a></h3>
<p>若要实现自定义的格式则要实现 <a class="reference internal" href="../api/Phalcon_Logger_FormatterInterface.html"><em>Phalcon\Logger\FormatterInterface</em></a> 接口，
这样才能扩展已有的格式或创建自定义的格式</p>
</div>
</div>
<div class="section" id="id1">
<h2>适配器(Adapters)<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
<p>下面的例子中展示了每种适配器的简单用法：</p>
<div class="section" id="stream-logger">
<h3>数据流日志记录器（Stream Logger）<a class="headerlink" href="#stream-logger" title="永久链接至标题">¶</a></h3>
<p>系统日志保存消息到一个已注册的有效的PHP流中。 这里列出了可用的流： here &lt;<a class="reference external" href="http://php.net/manual/en/wrappers.php">http://php.net/manual/en/wrappers.php</a>&gt;`_:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\Stream</span> <span class="k">as</span> <span class="nx">StreamAdapter</span><span class="p">;</span>

<span class="c1">// 使用zlib压缩流</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">StreamAdapter</span><span class="p">(</span><span class="s2">&quot;compress.zlib://week.log.gz&quot;</span><span class="p">);</span>

<span class="c1">// 发送消息到stderr</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">StreamAdapter</span><span class="p">(</span><span class="s2">&quot;php://stderr&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="file-logger">
<h3>文件日志记录器（File Logger）<a class="headerlink" href="#file-logger" title="永久链接至标题">¶</a></h3>
<p>文件适配器保存所有的日志信息到普通的文件中。 默认情况下日志文件使用添加模式打开，打开文件后文件的指针会指向文件的尾端。
如果文件不存在，则会尝试创建。 我们可以通过传递附加参数的形式来修改打开的模式：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\File</span> <span class="k">as</span> <span class="nx">FileAdapter</span><span class="p">;</span>

<span class="c1">// 使用写模式打开</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileAdapter</span><span class="p">(</span>
    <span class="s2">&quot;app/logs/test.log&quot;</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="s2">&quot;mode&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;w&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="syslog-syslog-logger">
<h3>Syslog 日志记录器（Syslog Logger）<a class="headerlink" href="#syslog-syslog-logger" title="永久链接至标题">¶</a></h3>
<p>使用系统日志适配器。 由于操作系统的不同得到的日志也不尽相同：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\Syslog</span> <span class="k">as</span> <span class="nx">SyslogAdapter</span><span class="p">;</span>

<span class="c1">// 基本用法</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SyslogAdapter</span><span class="p">(</span><span class="k">null</span><span class="p">);</span>

<span class="c1">// Setting ident/mode/facility 参数设置</span>
<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SyslogAdapter</span><span class="p">(</span>
    <span class="s2">&quot;ident-name&quot;</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="s2">&quot;option&quot;</span>   <span class="o">=&gt;</span> <span class="nx">LOG_NDELAY</span><span class="p">,</span>
        <span class="s2">&quot;facility&quot;</span> <span class="o">=&gt;</span> <span class="nx">LOG_MAIL</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="firephp-firephp-logger">
<h3>FirePHP 日志记录器（FirePHP Logger）<a class="headerlink" href="#firephp-firephp-logger" title="永久链接至标题">¶</a></h3>
<p>This logger sends messages in HTTP response headers that are displayed by <a class="reference external" href="http://www.firephp.org/">FirePHP</a>,
a <a class="reference external" href="http://getfirebug.com/">Firebug</a> extension for Firefox.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Logger</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Logger\Adapter\Firephp</span> <span class="k">as</span> <span class="nx">Firephp</span><span class="p">;</span>

<span class="nv">$logger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Firephp</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">);</span>



<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is a message&quot;</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">log</span><span class="p">(</span>
    <span class="s2">&quot;This is an error&quot;</span><span class="p">,</span>
    <span class="nx">Logger</span><span class="o">::</span><span class="na">ERROR</span>
<span class="p">);</span>

<span class="nv">$logger</span><span class="o">-&gt;</span><span class="na">error</span><span class="p">(</span>
    <span class="s2">&quot;This is another error&quot;</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="implementing-your-own-adapters">
<h3>自定义适配器（Implementing your own adapters）<a class="headerlink" href="#implementing-your-own-adapters" title="永久链接至标题">¶</a></h3>
<p>如果开发者想自定义新的日志组件则需实现此接口： <a class="reference internal" href="../api/Phalcon_Logger_AdapterInterface.html"><em>Phalcon\Logger\AdapterInterface</em></a> 。</p>
</div>
</div>
</div>


                    </div>
                  </div>
                </div>
            </div>
          </td>
        </tr>
      </table>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="annotations.html" title="注释解析器（Annotations Parser）"
             >下一页</a> |</li>
        <li class="right" >
          <a href="loader.html" title="Class Autoloader"
             >上一页</a> |</li> 
      </ul>
    </div>

      <div class="prefooter">
  <div class="container">
      <div class="row">
          <div class="col-sm-3 text-right">
              <span>Follow along:</span>
          </div>
          <div class="col-sm-6 text-center">
              <a href="https://twitter.com/phalconphp" alt="Twitter" class="btn-social btn-social-twitter"><i class="icon-twitter"></i></a>
              <a href="https://www.facebook.com/pages/Phalcon-Framework/134230726685897" alt="Facebook" class="btn-social btn-social-facebook"><i class="icon-facebook"></i></a>
              <a href="https://plus.google.com/102376109340560896457" alt="Google+" class="btn-social btn-social-googleplus"><i class="icon-googleplus"></i></a>
              <a href="https://github.com/phalcon/cphalcon" alt="Github" class="btn-social btn-social-github"><i class="icon-github"></i></a>
          </div>
          <div class="col-sm-3">
          </div>
      </div>
  </div>

</div>
<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-xs-4 col-sm-3">
                <h4>Download</h4>
                <ul>
                    <li><a href="/download">Installing Phalcon PHP</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                    <li><a href="http://api.phalconphp.com">API</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html">Tutorial</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html#sample-applications">Sample Applications</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-3">
                <h4>Community</h4>
                <ul>
                    <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon">GitHub</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon/issues">Issue Tracker</a></li>
                    <li><a href="http://stackoverflow.com/questions/tagged/phalcon">Stack Overflow</a></li>
                    <li><a href="/en/testimonials">Testimonials</a></li>
                    <li><a href="http://builtwith.phalconphp.com/">Built with Phalcon</a></li>
                    <li><a href="http://store.phalconphp.com/">Store</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-2">
                <h4>About</h4>
                <ul>
                    <li><a class="link-black" href="http://blog.phalconphp.com/">Blog</a></li>
                    <li><a href="/en/about">About</a></li>
                    <li><a href="/en/team">Team</a></li>
                    <li><a href="/en/roadmap">Roadmap</a></li>
                    <li><a href="/en/donate">Donate</a></li>
                    <li><a href="/en/consulting">Consulting</a></li>
                    <li><a href="/en/hosting">Hosting</a></li>
                </ul>
            </div>
            <div id="license-spaccer" class="visible-xs"></div>
            <div id="license-wrapper" class="col-xs-12 col-sm-4">
                <p class="license">
                    Phalcon is an open-source PHP framework <br>built as a C-extension. It is available under the <br>
                    <a href="http://opensource.org/licenses/BSD-3-Clause" target="_blank">new BSD License</a>.
                    <br>
                    <br>
                    Except where otherwise noted, content on this site is licensed under the
                    <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License.</a>
                </p>
            </div>
        </div>
    </div>
</footer>

    </div>
    <script type="text/javascript">
    $(window).on("load", function(){
      var cx = '009733439235723428699:lh9ltjgvdz8';
      var gcse = document.createElement('script');
      gcse.type = 'text/javascript';
      gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(gcse, s);
    });
    </script>

  </body>
</html>